// const fs = require('fs')
// const path = require('path')
//
//
//
// let isDev = process.env.NODE_ENV !== 'production';
// let configPath = isDev ?  path.join(__dirname,'../extraResources/config.js') : path.join(process.resourcesPath, 'extraResources/config.js');
// console.log(`config path:${configPath}`)
// const config = require(configPath);

/**
 * 填充账号密码
 * @type {number}
 */
/*var timer1 = setInterval(() => {
    let dom = document.getElementById("field-email-3#")
    if(dom){
        const id = 'http://www.merchantwords.com'

        let account = getAccount(id);

        var usernameDom = document.getElementById("field-email-3#")
        var passwordDom = document.getElementById("field-pass-3#")
        var subSpan = document.querySelector('#submitButton > span');
        usernameDom.value = account.userName
        passwordDom.value = account.password
        usernameDom.setAttribute("style","display:none")
        passwordDom.setAttribute("style","display:none")
        console.dir(subSpan)
        subSpan.innerText = '人机验证通过,点我登录,无需输入账号密码！！！'
        clearOn()
    }
},200)*/

// var timer2 = setInterval(() => {
//
//     const id = 'https://members.junglescout.com/'
//
//     let account = getAccount(id);
//
//     let formDom = document.getElementsByClassName("TextInputWrapper-sc-1tsvy2y-0")
//
//     if(!formDom){
//         return;
//     }
//
//     var username = formDom[0];
//     var password = formDom[1];
//   username && username.select();
//   username && username.setAttribute('value',account.userName)
//   password && password.setAttribute('value',account.password)
//     clearTwo()
// },200)

/**
 * 更换搜索提示语
 * @type {number}
 */
// var timer3 = setInterval(() => {
//     var searchDom = document.getElementById("usersearchbox")
//     if(searchDom){
//         searchDom.setAttribute('placeholder',`  搜索间隔请控制在${config.control.interval_time/1000}秒内  低于规定时间无法搜索！！！`)
//         clearThree();
//     }
// },200)

/**
 * 禁用聊天组件
 * @type {number}
 */
// var timer4 = setInterval(() => {
//     var IMDom = document.getElementById("launcher");
//     if(IMDom){
//         IMDom.setAttribute('style','display:none')
//         clearFour();
//     }
// },1000)

/**
 * 禁用账户图标
 * @type {number}
 */
// var timer5 = setInterval(function () {
//     var nav = document.getElementsByClassName('nav')
//     if(!nav){
//         return;
//     }
//     nav[0] && nav[0].setAttribute('style','display:none')
// },200)

var timer6 = setInterval(function () {

    var account = document.getElementsByClassName('AccountInfo-ixx03q-10');
    var msg = document.getElementsByClassName('DropdownTrigger-sc-1bcx7cp-2');

    if(!account || account.length === 0){
        return;
    }
    msg[0].setAttribute('style','display:none')
    account[0].setAttribute('style','display:none')
    clearSix();
},500)

var timer7 = setInterval(function () {
    var a = document.getElementsByClassName('list-account-items');

    if(!a){
        return;
    }
    a[0] && a[0].setAttribute('style','display:none')
    clearSeven();
},1000)

var timer8 = setInterval(() => {
    var b = document.getElementById('pendo-image-wrapper-62e6c736');
    if(!b){
        return;
    }
    b.setAttribute('style','display:none')
},500)

function clearOn() {
    clearInterval(timer1)
}

function getAccount(id) {
    let accounts = fs.readFileSync(config.control.baseResourceDir + '/config.json','utf8');
    accounts = JSON.parse(accounts);

    let account;
    for (let a of accounts){
        if(a.id == id){
            account = a.account;
            break;
        }
    }
    return account;
}

function clearTwo() {
    clearInterval(timer2)
}

function clearThree() {
    clearInterval(timer3)
}
function clearFour() {
    clearInterval(timer4)
}
function clearFive() {
    clearInterval(timer5)
}
function clearSix() {
    clearInterval(timer6)
}
function clearSeven() {
    clearInterval(timer7)
}
